import utils  from "@/utils/function.js"
const  { request } = utils
class Paging {
    constructor(url,query = {page:1}){
        this.url = url
        this.query = query
    }

    /**
     * 请求分页数据
     */
    request(){
        this.query = _.assign({},this.query,this._objRemoveUndefined(arguments[0]));
        return request.loading().get(this.url,this.query)
    }

    /**
     * 筛选对象中的Undefined
     * @param {*} obj
     */
    _objRemoveUndefined(obj){
        let ret = {};
        _.forOwn(obj,(value, key)=>{
            if(!_.isUndefined(obj[key])){
                ret[key] = value
            }
        })

        return ret;
    }

    /**
     * 设置查询参数
     * @param {*} data
     */
    setQuery(data){
        this.query = _.assign(this.query,this._objRemoveUndefined(data))
        //console.log(this.query)
    }

    /**
     * 获取查询参数
     */
    getQuery(){
        return this.query
    }
}

export default Paging
